package com.navinfo.tripanalysis.common.arithmetic;

import com.navinfo.tripanalysis.common.arithmetic.common.*;
import com.navinfo.tripanalysis.common.arithmetic.annotation.Arithmetic;
import com.navinfo.tripanalysis.common.arithmetic.common.VarCommon;
import com.navinfo.tripanalysis.common.arithmetic.common.VarRangeData;
import com.navinfo.tripanalysis.common.arithmetic.manager.AbstractArithmetic;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * 24小时区间统计算法<br/>
 * 依赖{@link Mileage}里程油耗算法<br/>
 * 输出：统计
 * @author wangshuai
 */
@Arithmetic(name = "24小时区间统计算法")
public class RangeClock extends AbstractArithmetic<VarRangeData> {

    @Override
    public void calculate() {
        logger.debug("开始24小时区间统计算法[terminalId:{}]", terminalId);
        CommonData commonData = drivingData.getCommonData();
        LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(commonData.getGpsTime()), ZoneId.systemDefault());

        //累加指定区间段的数据
        VarCommon rangeData = getObj().getRangeData(dateTime.getHour());
        rangeData.addMileage(commonData.getDffDistance());
        rangeData.addFuel(commonData.getDffOil());
        rangeData.addDuration(commonData.getDffTime());
        logger.debug("结束24小时区间统计算法[terminalId:{}]", terminalId);
    }

    @Override
    public void collect(OuterStatisticData statisticDataOut) {
        statisticDataOut.setClockRanges(getObj().convertRanges());
    }
}
